<template>
  <div>
    <van-nav-bar title="模拟扫描" left-text="返回" left-arrow @click-left="onClickLeft"/>
  </div>
  <div style="text-align: center;margin-top: 50%;">
    <span><van-button round type="success" size="small" @click="goCharging()">扫码完成</van-button></span>
  </div>
</template>
<script setup>
import router from '@/router';
import {RandomAvailableGun} from "@/api/station";
import {ref} from "vue";

const onClickLeft = () => history.back();

const gunInfo = ref(null);

init();

function init() {
  RandomAvailableGun().then(res => {
    console.info('获取到可用的充电枪', res.data.data);
    if (res.data.code === 200000) {
      gunInfo.value = res.data.data;
    } else {
      console.info('没有可用的充电枪');
    }
  }).catch(err => {
    console.error('获取可用的充电枪失败', err);
  });
}

function goCharging() {
  router.push({
    path: '/charging/start',
    query: {gunId: gunInfo.value.id}});
}
</script>